import React, { Component } from 'react';
import {
  KeyboardAvoidingView, Platform,
  StyleSheet, Text, TextInput,
  PixelRatio, View, Image, ScrollView,
  TouchableOpacity,
  DeviceEventEmitter
} from "react-native";
import { GLOBAL } from '../../../config/global';
import { style } from '../../../theme/style';
import { Common } from '../../../component/common/Common.js';
import { Button } from '../../../components/form/button';
import { RelevanceCpt } from './_components/RelevanceCpt';
import { API, API_GENERATE } from '../../../config/api';
import HTTP from '../../../utils/http';
import ToastUtil from '../../../utils/toast';
import OrderCreactService from './_common/service'
import { Loading } from '../../../component/page-status/Pageloading';
import { orderBaseStyle } from './_common/style.js';
import MethodUtil from '../../../utils/MethodUtil';
import Dictionary from '../../../utils/dictionary';

import { BottomCpt } from '../_components/BottomCpt';
import { BouncedCpt } from '../_components/BouncedCpt';
import { BodyCpt } from '../_components/BodyCpt';

const scale = GLOBAL.SCALE;
const selectIcon = require('../../../imgs/global/down.png');
export class relevanceOrderList extends Component {
  static navigationOptions = ({ navigation }) => {
    return {
      headerTitle: '计划关联',
      headerLeft: <Common type="headLeft" onPress={() => { navigation.goBack(); DeviceEventEmitter.emit("relevanceOrderList", { relevanceOrderList: true }); }} />,
      headerRight: (<Image style={style.head.headRightEmpty} source={require('../../../imgs/goBackEmpty.png')} />),
      headerStyle: {  // 头部整体样式 
        elevation: 0,
        backgroundColor: '#f7f7f7',
        borderBottomWidth: 0
      },
      headerTitleStyle: {
        flex: 1,
        textAlign: 'center'
      }
    }
  };

  requesting
  constructor(props) {
    super(props);
    console.log('params', props.navigation.state.params)
    let { resultData, showPrice, orderFlag } = props.navigation.state.params || {};
    let { orderItemList, orderFeeList, orderInfo } = resultData || {};
    let { orderType } = orderInfo || {};
    this.state = {
      tabIndex: orderType == 'P' ? 0 : 1,
      totalPlanGrossProfit: 0,
      totalMappingProfit: 0,
      showRules: false,
      orderTotalQuantity: 0, //毛利计算规则展示的订单总量
      orderFees: 0, //毛利计算规则展示的杂费
      orderTotalMapping: 0, //毛利计算规则展示的总关联量
      orderData: resultData || {},
      isVisible: false, //底部弹框
      isDetailsVisible: false, //底部弹框
      isModal: false,
      isModal: false,
      mappingIndex: 0,
      orderMappingIndex: 0,
      orderMappingInfo: [],
      OD_ZXY_PORT: []
    }

    this.resetPage = OrderCreactService.reset.bind(this);
    this.productsList = orderItemList || [];
    this.orderFeeList = orderFeeList || [];
    this.orderInfo = orderInfo || {};
    this.status = false;
    this.showPrice = showPrice || {}; // 底部弹框
    this.orderFlag = orderFlag || {};
    this.detailsData = {}; // 上一个页面传递参数
    this.detailsDataAll = {}; // 详情全的参数
  }

  async componentWillMount() {
    await this.init();
    await this.getOrderRpt();
    await this.getOrderMapping();
  }

  init = async () => {
    let OD_ZXY_PORT = await Dictionary.get('OD_ZXY_PORT');
    let orderTotalQuantity = 0;
    let orderFees = 0;
    this.productsList.map((item, index) => {
      orderTotalQuantity = orderTotalQuantity + parseFloat(item.quantity)
    })
    this.orderFeeList.map((item, index) => {
      orderFees = orderFees + parseFloat(item.feeAmt)
    })
    this._detailsSend();
    this.setState({
      orderTotalQuantity,
      orderFees,
      OD_ZXY_PORT
    })
  }

  //查询意向
  async getOrderRpt() {
    let response = await HTTP.POST(API_GENERATE(API.GET_ORDER_RPTEXT), { orderId: this.orderInfo.orderId });
    let releaeData;
    if (!response || !response.length) {
      response = [];
      this.productsList.map((item, index) => {
        response[index] = {};
        response[index]['goodsName'] = item.goodsName;
        response[index]['goodsId'] = item.goodsId;
        response[index]['totalQuantity'] = item.quantity;
        response[index]['orderId'] = this.orderInfo.orderId;
      })
    } else {
      //计算合计利润
      this.releaseData({ data: response, type: 0 });
    }
  }

  //点击新增销售意向
  addRpt(index) {
    const { orderRptInfo } = this.state;
    this.props.navigation.navigate('relevanceAddPage', {
      orderRptInfo: orderRptInfo[index],
      callBack: (data) => {
        let { orderRptInfo } = this.state;
        this.releaseData({ data: orderRptInfo, addItem: data, goodsId: data.goodsId, type: 1 });
      }
    })
  }

  //修改意向数据
  changeData(inputValue, goodsId, index, type) {
    let { orderRptInfo } = this.state;
    this.releaseData({ data: orderRptInfo, inputValue, goodsId, index, type });
  }

	/*
	 * 计算意向总量和利润
	 * type - 0初始化数据 1新增数据 2删除数据 3修改数量 4修改金额
	*/
  releaseData(params) {
    let { data, addItem, inputValue, goodsId, index, type } = params;
    let totalPlanGrossProfit = 0;
    let totalPlanQuan = 0;
    let planGrossProfit = 0;
    data && data.map(list => {
      list.rptExtList = list.rptExtList || [];

      if (type) {
        if (list.goodsId === goodsId) {
          if (type === 1) {
            list.rptExtList.push(addItem);
          } else if (type === 2) {
            list.rptExtList.splice(index, 1);
          } else if (type === 3) {
            // inputValue = inputValue.match(/^\d*(\.?\d{0,3})/g)[0] || null;
            list.rptExtList[index].planSellQuantity = parseFloat(inputValue || 0);
          } else {
            list.rptExtList[index].planSellPrice = parseFloat(inputValue || 0);
          }

          list.rptExtList && list.rptExtList.length && list.rptExtList.map((rpt, j) => {
            let unprice = this.orderInfo.orderType === 'P' ? (rpt.planSellPrice - list.price) : (list.price - rpt.planSellPrice);
            totalPlanQuan = totalPlanQuan + rpt.planSellQuantity;
            rpt.planGrossProfit = parseFloat(rpt.planSellQuantity) * parseFloat(unprice);
            planGrossProfit = planGrossProfit + rpt.planGrossProfit;

          })
          list.planSellQuantity = totalPlanQuan;
          list.planGrossProfit = planGrossProfit;
        }

        totalPlanGrossProfit = totalPlanGrossProfit + list.planGrossProfit;
      } else {
        list.rptExtList && list.rptExtList.length && list.rptExtList.map((rpt, j) => {
          let unprice = this.orderInfo.orderType === 'P' ? (rpt.planSellPrice - list.price) : (list.price - rpt.planSellPrice);
          totalPlanQuan = totalPlanQuan + rpt.planSellQuantity;
          rpt.planGrossProfit = parseFloat(rpt.planSellQuantity) * parseFloat(unprice);
          planGrossProfit = planGrossProfit + rpt.planGrossProfit;
        })
        list.planSellQuantity = totalPlanQuan;
        list.planGrossProfit = planGrossProfit;
        totalPlanGrossProfit = totalPlanGrossProfit + list.planGrossProfit;
      }
    })

    this.setState({
      orderRptInfo: data,
      totalPlanGrossProfit
    })

    // return { data, totalPlanGrossProfit };
  }
  //草稿（新增）查询本地已关联列表-new  
  async getOrderMapping() {
    let { orderData, OD_ZXY_PORT, mappingIndex, orderMappingIndex } = this.state;
    let { orderFlag } = orderData || {};
    let totalMappingProfit = 0;
    let orderTotalMapping = 0;
    let response = await HTTP.POST(API_GENERATE(API.LOCAL_USED_MAPPING_LIST), { orderId: this.orderInfo.orderId, orderType: this.orderInfo.orderType });
    if (!response || !response.length) {
      response = [];
      this.productsList.map((item, index) => {
        response[index] = {};
        response[index]['groupName'] = item.goodsName;
        response[index]['availableQuantity'] = item.quantity;
        response[index]['totalQuantity'] = item.quantity;
        response[index]['orderInfo'] = {};
        response[index]['orderInfo']['goodsId'] = item.goodsId;
        response[index]['orderInfo']['batchNo'] = item.batchNo;
        response[index]['orderInfo']['orderId'] = this.orderInfo.orderId;
        response[index]['orderInfo']['orderType'] = this.orderInfo.orderType;
        response[index]['orderInfo']['companyName'] = this.orderInfo.companyName;
      })
    } else {
      /* 
        average : 均价  均价 = (关联总价格 / 关联总数量 )   关联总价格 = 多个关联累加(关联价格*关联数量)
        expectALl : 总毛利  关联3个订单 3个毛利累加 就是 总毛利
        expect : 预计毛利   (采)预计毛利 =( 均价(关联销售) - 落代价)
      */
      response.map((item, index) => {
        let quantity = 0;
        let mappingFees = 0;
        let expectALl = 0; //总毛利
        let expect = 0; //预计毛利
        let average = this._average(item.stockMappingList) || 0; // 均价 
        let { pocketPrice } = this.detailsData.orderPriceItemList[index] || {};
        item.pocketPrice = pocketPrice || 0; //落袋价
        if (orderFlag.orderType == 'P') {
          expect = MethodUtil.countObj.subtract((average || 0), (item.pocketPrice || 0));// //计算规则 -> 预计毛利     (采)预计毛利 =( 均价(关联销售) - 落代价)
        } else {
          expect = MethodUtil.countObj.subtract((item.pocketPrice || 0), (average || 0));// //计算规则 -> 预计毛利 
        }

        item.stockMappingList && item.stockMappingList.map(async (mapping, i) => {
          const { lockedTO, orderInfo } = mapping;
          // 单商品总关联数量
          quantity = quantity + lockedTO.lockedQuantity;
          item.lockedQuantity = quantity;
          // 单关联毛利
          mapping.expectSingle = MethodUtil.countObj.multiply(expect, lockedTO.lockedQuantity, 2);
          // 单商品总毛利
          expectALl = MethodUtil.countObj.add(expectALl, mapping.expectSingle, 2)
          //ZXY_PORT初始化报关弹框
          if (orderInfo.ywType == 'ZXY') {
            OD_ZXY_PORT.map((item, portindex) => {
              if (item.dictKey == lockedTO.portKey) {
                lockedTO.selectedIndex = portindex;
                mappingIndex = i;
                orderMappingIndex = index;
              }
            })
          }
          // 获取关联订单的杂费,XC-API.ZXY_ORDER_INFO
          let response = await HTTP[orderInfo.ywType == 'ZXY' ? 'GET' : 'POST'](API_GENERATE(orderInfo.ywType == 'ZXY' ? API.ZXY_ORDER_INFO : API.FIND_ORDER), { orderId: orderInfo.orderId });
          let orderFees = 0;
          if (response) {
            let orderFeeList = orderInfo.ywType == 'ZXY' ? response.orderFeeList : response.zxyOrderFeeVOs;
            orderFeeList && orderFeeList.length && orderFeeList.map((item, index) => {
              let itemfee = orderInfo.ywType == 'ZXY' ? parseFloat(item.feeAmt || 0) * parseFloat(orderInfo.pbocPrice || 0) : parseFloat(item.feeAmt || 0);
              orderFees = orderFees + (itemfee || 0);
            })
          }
          mappingFees = mappingFees + orderFees;
        })
        this.productsList.map((proItem, index) => {
          if (proItem.goodsId === item.orderInfo.goodsId) {
            //单商品总（待关）量
            item.totalQuantity = proItem.quantity || 0;
            // 单商品总待关联量=单商品总量-单商品已关联量
            item.availableQuantity = (proItem.quantity || 0) - (item.lockedQuantity || 0);
          }
        })
        // 订单总毛利
        totalMappingProfit = totalMappingProfit + (expectALl || 0);
        // 毛利计算规则展示该订单总关联量
        orderTotalMapping = orderTotalMapping + (item.lockedQuantity || 0);
        // 均价
        item.average = average;
        // 预计毛利
        item.expect = expect;
        // 总毛利
        item.expectALl = expectALl;
        // 单商品杂费
        item.mappingFees = mappingFees;
      })
    }
    this.setState({
      orderMappingInfo: response,
      totalMappingProfit,
      orderTotalMapping,
      mappingIndex,
      orderMappingIndex
    })
  }


  //输入关联数量
  changeMapping(txt, productIndex, mappingIndex) {
    let { orderMappingInfo, orderData } = this.state;
    let { orderFlag } = orderData || {};
    let totalMappingProfit = 0;
    let orderTotalMapping = 0;

    orderMappingInfo && orderMappingInfo.length && orderMappingInfo.map((item, index) => {
      let expectALl = 0;//单商品总毛利
      let totalQuan = 0;// 单商品总关联量
      let expect = 0; //预计毛利
      let average = 0;
      item.stockMappingList && item.stockMappingList.length && item.stockMappingList.map((mapping, indexM) => {
        const { lockedTO } = mapping;
        if (productIndex === index && mappingIndex === indexM) {
          lockedTO.lockedQuantity = parseFloat(txt || 0);
        }
      })
      average = this._average(item.stockMappingList) || 0; // 均价 
      if (orderFlag.orderType == 'P') {
        expect = MethodUtil.countObj.subtract(average, (item.pocketPrice || 0));// //计算规则 -> 预计毛利     (采)预计毛利 =( 均价(关联销售) - 落代价)
      } else {
        expect = MethodUtil.countObj.subtract((item.pocketPrice || 0), average);// //计算规则 -> 预计毛利 
      }
      item.stockMappingList && item.stockMappingList.length && item.stockMappingList.map((mapping, indexM) => {
        const { lockedTO } = mapping;
        totalQuan = totalQuan + lockedTO.lockedQuantity;
        // 单关联毛利
        mapping.expectSingle = MethodUtil.countObj.multiply(expect, lockedTO.lockedQuantity, 2);
        // 单商品总毛利
        expectALl = MethodUtil.countObj.add(expectALl, mapping.expectSingle, 2);
      })
      if (productIndex === index) {
        // 单商品总关联量
        item.lockedQuantity = totalQuan;
        // 单商品总毛利
        item.expectALl = expectALl;
      }
      // 均价
      item.average = average;
      // 预计毛利
      item.expect = expect;
      // 计算合计利润
      totalMappingProfit = totalMappingProfit + (item.expectALl || 0);
      //毛利计算规则展示该订单总关联量
      orderTotalMapping = orderTotalMapping + (item.lockedQuantity || 0);
    })

    this.setState({
      orderMappingInfo,
      totalMappingProfit,
      orderTotalMapping
    })
  }

  //光标移出校验
  checkQuantity(groupName, lockedQuantity, availableQuantity, expectSingleLockedQuantity, expectSingleAvailableQuantity) {
    const { orderTotalMapping } = this.state;
    let { showPrice } = this.props.navigation.state.params || {};
    let { orderPriceInfo } = showPrice || {};
    let { totalOrderQuantity } = orderPriceInfo || {};
    let inputMapping = parseFloat(this.curItemInputText || lockedQuantity || 0);
    let onMapping = parseFloat(availableQuantity)
    if (inputMapping <= 0) {
      ToastUtil.showWarning('关联量必须大于0');
      return false;
    }
    //接口可关字段有问题，暂时注释校验
    if (inputMapping > onMapping) {
      ToastUtil.showWarning('关联量不能大于可关联量');
      return false;
    }
    if (expectSingleLockedQuantity > expectSingleAvailableQuantity) {
      ToastUtil.showWarning(`${groupName}关联总量不能大于待关联量`);
      return false;
    }
    if (orderTotalMapping > totalOrderQuantity) {
      ToastUtil.showWarning('已关联量不能大于订单总量');
      return false;
    }
  }

  addMapping(index, orderInfo) {
    const { orderMappingInfo } = this.state;
    // const { quantity } = this.productsList[index] || {};
    // orderMappingInfo[index].totalQuantity = quantity;
    this.props.navigation.navigate('projectListPage', {
      orderMappingInfo: orderMappingInfo[index],
      orderInfo,
      callBack: (data) => {
        this.getOrderMapping();
      }
    })
  }

  //删除关联计划
  async _removeMappingItemFn(productIndex, mappingIndex) {
    let { orderMappingInfo } = this.state;
    if (orderMappingInfo && orderMappingInfo.length) {
      this.delMapping(orderMappingInfo[productIndex].orderInfo, orderMappingInfo[productIndex].stockMappingList[mappingIndex]);
      orderMappingInfo[productIndex].stockMappingList.splice(mappingIndex, 1);
    }
  }
  //删除关联计划
  async delMapping(productInfo, mappingItem) {
    const { orderId, orderType, batchNo } = productInfo || {};
    const { orderInfo } = mappingItem || {};
    let params = {
      orderId, orderType, batchNo,
      mappingOrderId: orderInfo.orderId,
      mappingBatchNo: orderInfo.batchNo
    }
    const response = await HTTP.POST(API_GENERATE(API.DEL_MAPPING_LIST), params);
    if (response) {
      await this.getOrderMapping();
    }
  }

  //保存-提交意向列表
  async saveRptList(submitType, submitResponse) {
    const { orderRptInfo } = this.state;
    let rptList = [];
    orderRptInfo.map((item, index) => {
      for (let i = 0; i < item.rptExtList.length; i++) {
        let checkItem = {
          extId: item.rptExtList[i].extId,
          orderId: item.orderId,
          itemId: item.itemId,
          companyId: item.rptExtList[i].companyId,
          companyAddressId: item.rptExtList[i].companyAddressId,
          planSellQuantity: item.rptExtList[i].planSellQuantity,
          planSellPrice: item.rptExtList[i].planSellPrice,
          planRecvType: item.rptExtList[i].planRecvType,
          planSellBeginDate: item.rptExtList[i].planSellBeginDate,
          planSellEndDate: item.rptExtList[i].planSellEndDate,
          planRemark: item.rptExtList[i].planRemark
        }

        if (item.rptExtList[i].planSellQuantity) {
          rptList.push(checkItem);
        }

      }
    })
    let params = {
      orderId: submitResponse.orderInfo.orderId, //提交或保存成功后返回的id
      rptExtList: rptList
    }
    const response = await HTTP.POST(API_GENERATE(API.ADD_RPTEXT), params);
    if (response) {
      await this.saveMapping(0, submitType, submitResponse);
    }
  }

  //保存-提交关联列表
  async saveMapping(type, submitType, submitResponse) {
    let { orderMappingInfo } = this.state;
    let orderMappingList = [];
    orderMappingInfo && orderMappingInfo.length && orderMappingInfo.map((item, index) => {
      const { stockMappingList, orderInfo } = item || {};
      const { orderId, orderType, batchNo, goodsId } = orderInfo || {};
      stockMappingList && stockMappingList.length && stockMappingList.map((stockMappingItem, i) => {
        const { lockedTO } = stockMappingItem;
        let checkItem = {
          orderId,
          orderType,
          batchNo,
          goodsId,
          mappingOrderId: stockMappingItem.orderInfo.orderId,
          mappingBatchNo: stockMappingItem.orderInfo.batchNo,
          mappingQuantity: lockedTO.lockedQuantity,
          portKey: lockedTO.portKey,
          ywType: stockMappingItem.orderInfo.ywType,
        }
        orderMappingList.push(checkItem);
      })
    })
    const addApi = submitType ? API.SUBMIT_MAPPING_LIST : API.LOCAL_SAVE_MAPPING_LIST
    const response = await HTTP.POST(API_GENERATE(addApi), orderMappingList);
    if (response && type !== 'delete') {
      let { orderData } = this.state;
      let { tCode, orderType } = orderData.orderFlag || {};

      let status = 0;
      if (tCode == 'E' && submitType == 1) {
        //RPT_AUDITING : 审批 , RPT_AUDIT_PASS : 进行中':
        status = this.status == 'RPT_AUDITING' ? '1' : '2';
      } else {
        status = submitType ? 1 : 0;
      }

      ToastUtil.showSuccess(submitType ? '提交成功' : '保存成功').then(() => {
        console.log('99999999-orderType', orderType, 'tCode', tCode, 'status', status, this.status)
        this.resetPage(orderType, tCode, status)
      })
    }
  }

  // 验证
  _verifyFn = () => {
    let { orderData } = this.state;
    let { orderInfo, orderItemList, orderDeliveryPlanList, orderFlag } = orderData || {};
    let { companyId, payType, tradeType, payStyle, deliveryType, lostRender, lostRateBig,
      srcAddressId, destAddressId, transportType } = orderInfo;
    let { orderType } = orderFlag;
    let { isLostRate } = this.state;



    //供应商/客户-验证
    if (!companyId) {
      ToastUtil.showWarning(`请选择${this.PageText.companyTitle}`);
      return false;
    }

    //付款类型-验证
    if (!payType) {
      ToastUtil.showWarning(`请选择${this.PageText.payTypeTitle}`);
      return false;
    } else if (tradeType !== 'O') {
      let payTypeArrPass = true;
      this.payTypeArr && this.payTypeArr.map(item => {
        if (!orderInfo[item.name]) {
          ToastUtil.showWarning(`请先填写完整${this.PageText.payTypeTitle}相关数据`);
          payTypeArrPass = false;
          return;
        }

        if (orderType === 'P' && item.name === 'deliveryExpireDays') {
          if (Number.parseFloat(orderInfo[item.name]) > Number.parseFloat(this.showData.accountDay)) {
            ToastUtil.showWarning(`本单授信账期必须小于等于授信账户账期天数`);
            payTypeArrPass = false;
            return;
          }
        }
        if (orderType === 'S' && item.name === 'payExpireDays') {
          if (Number.parseFloat(orderInfo[item.name]) > Number.parseFloat(this.showData.accountDay)) {
            ToastUtil.showWarning(`付款天数必须小于等于账期天数`);
            payTypeArrPass = false;
            return;
          }
        }
      })

      if (!payTypeArrPass) return payTypeArrPass
    }

    //付款(收款)方式-验证
    if (!payStyle) {
      ToastUtil.showWarning(`请选择${this.PageText.payMethodTitle}`);
      return false;
    }

    //交货方式-验证
    if (!deliveryType) {
      ToastUtil.showWarning('请先选择交货方式');
      return false;
    }

    //交货地验证
    if (this.isVerify.startAddress && !srcAddressId) {
      ToastUtil.showWarning('请先选择出库地');
      return false;
    }
    if (this.isVerify.endAddress && !destAddressId) {
      ToastUtil.showWarning('请先选择目的地');
      return false;
    }
    //运输方式
    if (this.isVerify.trans && !transportType) {
      ToastUtil.showWarning('请先选择运输方式');
      return false;
    }

    //商品列表验证
    if (orderItemList && orderItemList.length <= 0) {
      ToastUtil.showWarning('请添加商品');
      return false
    }
    //交货计划列表
    if (orderDeliveryPlanList && orderDeliveryPlanList.length <= 0) {
      ToastUtil.showWarning('请添加交货计划');
      return false
    }

    return true;

  }

  //提交(下一步) submitType==0 保存 ，submitType==1 提交
  _nextFn = async (submitType) => {
    if (this.requesting) return;
    this.requesting = true;
    let rptFilter;
    let mappingFilter;
    let { orderData, orderRptInfo, orderMappingInfo } = this.state;
    let { tCode, orderType } = orderData.orderFlag || {};

    //校验意向
    orderRptInfo.map((item, index) => {
      if (item.rptExtList && item.rptExtList.length > 0) {
        for (let i = 0; i < item.rptExtList.length; i++) {
          if (!submitType) {
            rptFilter = true; //保存、删除操作不做校验，提交再做校验
            return;
          } else {
            rptFilter = this.filter(0, { itemPlanQuantity: item.rptExtList[i].planSellQuantity, listPlanQuantity: item.planSellQuantity, totalQuantity: item.totalQuantity });
          }
        }
      } else {
        rptFilter = true;
      }
    })

    //校验关联
    orderMappingInfo.every((item, index) => {
      const { orderTotalMapping } = this.state;
      let { showPrice } = this.props.navigation.state.params || {};
      let { orderPriceInfo } = showPrice || {};
      //订单总量，即多商品可关联总量
      let { totalOrderQuantity } = orderPriceInfo || {};
      //单商品数量，即单商品可关联总量
      if (item.stockMappingList && item.stockMappingList.length > 0) {
        for (let i = 0; i < item.stockMappingList.length; i++) {
          mappingFilter = this.filter(1, {
            itemPlanQuantity: item.stockMappingList[i].lockedTO.lockedQuantity,
            listPlanQuantity: orderTotalMapping,
            totalQuantity: totalOrderQuantity,
            itemTotalQuantity: item.lockedQuantity,
            itemAvailableQuantity: item.totalQuantity,
            groupName: item.groupName,
            portKey: item.stockMappingList[i].lockedTO.portKey,
            ywType: item.stockMappingList[i].orderInfo.ywType,
            mappingOrderId: item.stockMappingList[i].orderInfo.orderId,
            expectSingle: item.stockMappingList[i].expectSingle,
            expectALl: item.expectALl
          });
          if (!mappingFilter) return;
        }
      } else {
        mappingFilter = true; //删除操作不做校验
      }

    })

    if (rptFilter && mappingFilter) {
      this.setState({ status: 'loading' });
      //提交特殊字段
      orderData.submit = 1;
      const api = submitType ? 'NEW_ORDER_SUBMIT_' : 'NEW_ORDER_OPEN_';
      let resultData = await HTTP.POST(API_GENERATE(API[api + (tCode == 'QH' ? 'E' : tCode)]), orderData);

      this.requesting = false;
      this.setState({ status: 'data' });
      setTimeout(() => {
        this.requesting = false;
      }, 500)
      if (resultData) {
        if (resultData.orderInfo.status) {
          this.status = resultData.orderInfo.status;
        }
        await this.saveRptList(submitType, resultData);
      }
    } else {
      this.requesting = false;
    }
  }

  _tabFn = (num) => {
    this.setState({
      tabIndex: num
    })
  }

  //提交订单
  _submitFn = (submitType) => {
    this._nextFn(submitType);
  }

	/*
	  * 校验
		* type==0 意向客户
		* type==1 销售成交
	*/
  filter(type, filterData) {
    const { itemPlanQuantity, listPlanQuantity, totalQuantity, itemTotalQuantity, itemAvailableQuantity, groupName, ywType, portKey, mappingOrderId,
      expectSingle, expectALl } = filterData;
    const label = type ? '计划' : '新增意向';
    if (itemPlanQuantity <= 0) {
      ToastUtil.showWarning(label + '关联量必须大于0！');
      return false;
    }
    if (ywType == 'ZXY' && !portKey) {
      ToastUtil.showWarning(`请选择${groupName}关联外采单号${mappingOrderId}报关港口`);
      return false;
    }
    // 单商品关联总量不可大于单商品待关联总量
    if (itemTotalQuantity > itemAvailableQuantity) {
      ToastUtil.showWarning(`${groupName}关联总量不能大于待关联量`);
      return false;
    }
    if (listPlanQuantity > totalQuantity) {
      ToastUtil.showWarning(label + '已关联量不能大于订单总量');
      return false;
    }
    // if (expectSingle <= 0) {
    //   ToastUtil.showWarning(`${groupName}关联${mappingOrderId}毛利必须大于零！`);
    //   return false;
    // }
    // if (expectALl <= 0) {
    //   ToastUtil.showWarning(`${groupName}预计毛利必须大于零！`);
    //   return false;
    // }
    // if (this._totalGrossProfitAmt() <= 0) {
    //   ToastUtil.showWarning(`订单总毛利必须大于零！`);
    //   return false;
    // }

    return true;
  }

  //意向
  _intentionView = () => {
    const { orderRptInfo } = this.state;
    return (
      <View>
        {
          orderRptInfo && orderRptInfo.length ?
            orderRptInfo.map((rptInfo, index) => {
              const { goodsId, goodsName, planSellQuantity, totalQuantity, rptExtList } = rptInfo;
              return (
                <View key={index} style={styles.itemBox}>
                  <Text style={[styles.headBtn, styles.headBtnActive]} onPress={() => { this.addRpt(index) }}>新增意向</Text>
                  <View style={[styles.head]}>
                    <Text style={styles.headTitle}>{goodsName ? (goodsName.length > 20 ? goodsName.substr(0, 20) + "..." : goodsName) : ""}</Text>
                    <Text style={styles.headInfo}>已关联: {(planSellQuantity || 0).toFixed(3) || 0} 吨 | 待关联: {parseFloat(totalQuantity - planSellQuantity).toFixed(3) || 0} 吨</Text>
                  </View>
                  {
                    rptExtList && rptExtList.length ?
                      rptExtList.map((item, i) => {
                        const { companyName, companyAddress, planRecvTypeName, planSellBeginDate, planSellEndDate } = item || {};
                        return (
                          <View key={i} style={styles.contian}>
                            <Text style={styles.removeText} onPress={() => { this.changeData(null, goodsId, i, 2) }}>删除</Text>
                            <Text numberOfLines={1} style={[styles.ctTitle]}>{companyName || ''}</Text>
                            <View>
                              <View style={styles.ctInputBox}>
                                <TextInput
                                  style={styles.ctInput}
                                  keyboardType='numeric'
                                  defaultValue={(item.planSellQuantity || 0) + ''}
                                  onChangeText={(txt) => { this.changeData(txt, goodsId, i, 3) }}
                                />
                                <Text style={styles.ctInputText}>{item.uomName || '吨'}</Text>
                              </View>
                              <View style={styles.ctInputBox}>
                                <TextInput
                                  style={styles.ctInput}
                                  keyboardType='numeric'
                                  defaultValue={(item.planSellPrice || 0) + ''}
                                  onChangeText={(txt) => { this.changeData(txt, goodsId, i, 4); }}
                                />
                                <Text style={styles.ctInputText}>元/{item.uomName || '吨'}</Text>
                                <Text style={[styles.ctInputText, styles.money]} >毛利：<Text style={styles.ctInputTextRed}>¥ {item.planGrossProfit.toFixed(2) || 0} 元</Text></Text>
                              </View>
                            </View>
                            <View style={styles.ctItem}>
                              <Text style={styles.ctItemLable}>付款类型</Text>
                              <Text style={styles.ctItemText}>{planRecvTypeName || ''}</Text>
                            </View>
                            <View style={styles.ctItem}>
                              <Text style={styles.ctItemLable}>销售时间</Text>
                              <Text style={styles.ctItemText}>{planSellBeginDate || ''}-{planSellEndDate || ''}</Text>
                            </View>
                            <View style={styles.ctItem}>
                              <Text style={styles.ctItemLable}>目的地</Text>
                              <Text style={styles.ctItemText}>{companyAddress || ''}</Text>
                            </View>
                          </View>)
                      }) : <View style={styles.emptyView}>
                        <Text style={style.emptyText}>暂无关联任何{this.orderInfo.orderType == 'P' ? '销售' : '采购'}意向</Text>
                      </View>
                  }
                </View>)
            }) : null
        }
      </View>
    )
  }


  //均价
  _average = (stockMappingList) => {  // 均价 = (关联总价格 / 关联总数量 )   关联总价格 = 多个关联累加(关联价格*关联数量)
    let tolPrice = 0;
    let tolQuantity = 0;
    stockMappingList && stockMappingList.forEach(item => {
      const { lockedTO, orderInfo } = item;
      tolQuantity = tolQuantity + (lockedTO.lockedQuantity || 0); //多个已关联总量
      tolPrice = tolPrice + (orderInfo.price || 0) * (lockedTO.lockedQuantity || 0);  //多个已关联总价
    })
    if (tolQuantity) {
      return MethodUtil.countObj.divide(tolPrice, tolQuantity, 2) || 0;
    } else {
      return 0
    }
  }

  // 计算详情数据 参数整合
  _detailsSend = () => {
    let { resultData, showPrice, orderFlag } = this.props.navigation.state.params || {};
    let { orderInfo } = resultData || {};
    let { logisticsFee, logisticsPrice } = orderInfo || {};
    let { orderPriceInfo, orderPriceItemList } = showPrice || {};
    let { fundCreditFee, fundVoucherFee, averageOtherCost } = orderPriceInfo || {};

    this.detailsData.yunfei = logisticsFee;
    // if (orderFlag.orderType == "S") { //销售 - 额外运费
    // 	this.detailsData.yunfei = logisticsFee || null; //额外运费(销售)
    // } else { //采购 - 运费成本
    // 	this.detailsData.yunfei = logisticsPrice || null; //运费成本(采购)
    // }
    this.detailsData.averageOtherCost = averageOtherCost || null; //杂费
    this.detailsData.fundCreditFee = fundCreditFee || null; //资金授信
    this.detailsData.fundVoucherFee = fundVoucherFee || null; //资金票据
    this.detailsData.orderPriceItemList = orderPriceItemList || [];
  }

  //计算底部弹框 总毛利
  _totalGrossProfitAmt = () => {
    const { orderMappingInfo } = this.state;
    let results = 0;
    orderMappingInfo && orderMappingInfo.forEach(item => {
      results = MethodUtil.countObj.add(results, item.expectALl);
    })
    return results;
  }

  //采购成交
  _sellView = () => {
    const { orderMappingInfo } = this.state;
    return (
      <View>
        {
          orderMappingInfo && orderMappingInfo.length ?
            orderMappingInfo.map((orderMapping, index) => {
              let { groupName, orderInfo, stockMappingList, lockedQuantity, availableQuantity, totalQuantity, average, expectALl, expect } = orderMapping;
              let { orderPriceItemList } = this.detailsData || {};
              let { price, pocketPrice } = orderPriceItemList[index] || {};
              return (
                <View key={index} style={styles.itemBox}>
                  <Text style={[styles.headBtn, styles.headBtnActive]} onPress={() => { this.addMapping(index, orderInfo) }}>关联{orderInfo.orderType == 'P' ? '销售' : '采购'}</Text>
                  <View style={[styles.head, styles.xian]}>
                    <View style={[styles.rowbt, styles.ptop]}>
                      <Text style={styles.bold}>{groupName ? (groupName.length > 20 ? groupName.substr(0, 20) + "..." : groupName) : ""}</Text>
                      <Text style={styles.bold}>¥ {average || '-'}元/吨</Text>
                    </View>
                    <View style={styles.rowbt}>
                      <View style={styles.rowItem}>
                        <Text style={styles.norl}>已关联</Text>
                        <Text style={styles.bold} >{parseFloat(lockedQuantity || 0).toFixed(3) || 0} 吨</Text>
                      </View>
                      <View style={styles.rowItem}>
                        <Text style={styles.norl}>待关联</Text>
                        <Text style={styles.bold} >{parseFloat(totalQuantity - (lockedQuantity || 0)).toFixed(3) || 0} 吨</Text>
                      </View>
                      <View style={styles.rowItem}>
                        <View style={styles.rowbt}>
                          <Text style={styles.norl}>总毛利</Text>
                          <Text style={[styles.norl, styles.themeColor]} onPress={() => { this._showDetialsTwo(true, { ...this.detailsData, average, expect, lockedQuantity, groupName, expectALl, totalQuantity, price, pocketPrice }) }} >[计算规则]</Text>
                        </View>
                        <View style={styles.rowbt}>
                          <Text style={[styles.bold, styles.colorRed]} >{(expectALl || 0).toFixed(2) || 0}元</Text>
                        </View>
                      </View>
                    </View>
                  </View>
                  {
                    stockMappingList && stockMappingList.length ?
                      stockMappingList.map((item, i) => {
                        const { lockedTO, orderInfo } = item;
                        const { lockedQuantity, availableQuantity, portKey, portName } = lockedTO || {};
                        const { companyName, orderId, price, currency, pbocPrice, dutyRate, vatRate } = orderInfo || {};
                        return (
                          <View key={i} style={[styles.contian]}>
                            <Text style={styles.removeText} onPress={() => { this._removeMappingItemFn(index, i) }}>删除</Text>
                            <Text numberOfLines={1} style={[styles.ctTitle]}>{companyName.length > 20 ? companyName.substr(0, 20) + "..." : companyName} | {orderId}</Text>
                            <View style={[styles.ctInputBox, { flexWrap: 'wrap' }]}>
                              <View style={styles.ctInputBox}>
                                <TextInput
                                  style={styles.ctInput}
                                  keyboardType='numeric'
                                  defaultValue={(lockedQuantity || 0) + ''}
                                  onBlur={() => this.checkQuantity(groupName, lockedQuantity, availableQuantity, orderMapping.lockedQuantity, totalQuantity)}
                                  onChangeText={(txt) => { this.changeMapping(txt, index, i); this.curItemInputText = txt; }}
                                />
                                <Text style={{ fontSize: 11 * scale }} >吨 |</Text>
                              </View>
                              <Text style={[{ fontSize: 11 * scale }, styles.money]} >¥ {(price || 0).toFixed(2)}元/吨 |</Text>
                              <Text style={[{ fontSize: 11 * scale }, styles.money]} >可关{availableQuantity || 0}吨 |</Text>
                              <Text style={[{ fontSize: 11 * scale }, styles.money]} >毛利：<Text style={styles.ctInputTextRed}>¥ {(item.expectSingle || 0).toFixed(2) || 0} 元</Text></Text>
                            </View>
                            {currency !== 'RMB' ? <Text style={{ fontSize: 11 * scale, opacity: .7, marginBottom: 8 * scale }}>（美金汇率：{pbocPrice} | 增值税税率：{vatRate} | 关税税率：{dutyRate}）</Text> : null}
                            {orderInfo.ywType == 'ZXY' ? <View style={styles.subtitle}>
                              <Text style={{ fontSize: 12 * scale, fontWeight: 'bold', color: style.color.lightRed }}><Text style={styles.ctInputTextRed}>* </Text>报关港口：</Text>
                              <TouchableOpacity style={styles.gangkouSelect} onPress={() => { this.setState({ isModal: true, mappingIndex: i, orderMappingIndex: index }) }}>
                                <Text style={{ fontSize: 11 * scale, color: style.color.darkGray }}>{portName || '请选择报关港口'}</Text>
                                <Image source={selectIcon} style={{ tintColor: style.color.darkGray }} />
                              </TouchableOpacity>
                            </View> : null}
                          </View>
                        )
                      }) : <View style={styles.emptyView}>
                        <Text style={styles.emptyText}>暂无关联任何{orderInfo.orderType == 'P' ? '销售' : '采购'}计划 </Text>
                      </View>
                  }
                </View>
              )
            }) : null
        }
      </View>
    )
  }

  //隐藏/关闭详情弹框
  _hideDetials = (boolean) => {
    this.setState({
      isVisible: boolean
    })
  }
  //隐藏/关闭 计算明细 弹框
  _hideDetialsTwo = (boolean) => {
    this.setState({
      isDetailsVisible: boolean
    })
  }

  _showDetialsTwo = (boolean, detaisData) => {
    this.detailsDataAll = detaisData;
    this.setState({
      isDetailsVisible: boolean
    })
  }

  //选择报关回调
  _selectCallBack = (index) => {
    let { orderMappingInfo, mappingIndex, OD_ZXY_PORT } = this.state;
    orderMappingInfo && orderMappingInfo.length && orderMappingInfo.map((item, j) => {
      const { stockMappingList } = item || {};
      stockMappingList && stockMappingList.length && stockMappingList.map((stockMappingItem, i) => {
        const { lockedTO } = stockMappingItem;
        lockedTO.portKey = mappingIndex == i ? OD_ZXY_PORT[index].dictKey : lockedTO.portKey;
        lockedTO.portName = mappingIndex == i ? OD_ZXY_PORT[index].dictName : lockedTO.portName;
        lockedTO.selectedIndex = mappingIndex == i ? index : lockedTO.selectedIndex;
      })
    })
    this.setState({
      isModal: false,
      orderMappingInfo
    })
  }

  //切换功能
  _toggle = (onoff) => {
    this.setState({
      isModal: onoff
    })
  }

  render() {
    let { tabIndex, showRules, isVisible, isDetailsVisible, orderMappingInfo, mappingIndex, orderMappingIndex, isModal,
      OD_ZXY_PORT } = this.state;
    let { resultData } = this.props.navigation.state.params || {};
    let { orderInfo } = resultData || {};
    let { orderType } = orderInfo || {};
    let { stockMappingList } = orderMappingInfo[orderMappingIndex] || {};
    let selectIndex;
    if (stockMappingList && stockMappingList.length) {
      let { lockedTO } = stockMappingList[mappingIndex] || {};
      let { selectedIndex } = lockedTO || {};
      selectIndex = selectedIndex;
    }
    let btnData = [];
    if (orderInfo && orderInfo.bidId) {
      btnData = [{ text: '提交订单', callback: () => { this._submitFn(1) }, btnPreActive: true }];
    } else {
      btnData = [
        { text: '保存', callback: () => { this._submitFn(0) } },
        { text: '提交订单', callback: () => { this._submitFn(1) } }
      ]
    }


    return (
      <View style={styles.container}>
        <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : null} keyboardVerticalOffset={20} >
          {
            orderType == 'P' ? (<View style={styles.tabBox}>
              <Text onPress={() => { this._tabFn(0) }} style={[styles.itemTab, tabIndex == 0 ? styles.itemTabActive : null]}>意向客户</Text>
              <Text onPress={() => { this._tabFn(1) }} style={[styles.itemTab, tabIndex == 1 ? styles.itemTabActive : null]}>{this.orderInfo.orderType == 'P' ? '销售' : '采购'}成交</Text>
            </View>) : null
          }
          <ScrollView style={{ marginBottom: 80 * scale }}>
            {
              orderType == 'P' ? (
                <View style={styles.infoBox}>
                  {tabIndex ? <Text style={styles.info}>*商品毛利单价=关联销售均价-（采购单价+授信资金单价+杂费资金均价+运费成本单价）</Text> : null}
                  {tabIndex ? <Text style={styles.info}>商品总毛利=关联量*毛利单价</Text> : null}
                </View>
              ) : (<View style={styles.infoBox}>
                <Text style={styles.info}>* 商品毛利单价=销售单价 -（关联采购均价+授信成本单价+票据成本单价+杂费成本单价 +运费成本单价）</Text>
                <Text style={styles.info}>* 商品总毛利=关联量*毛利单价</Text>
                <Text style={styles.info}>* 美金转换人民币：美金单价*美金汇率 *（1+商品关税率）*（1+商品增值税税率）</Text>
              </View>)
            }

            {tabIndex ? this._sellView() : this._intentionView()}
          </ScrollView>

        </KeyboardAvoidingView>
        {/* <View style={styles.btnBox}>
					{!orderInfo.bidId && <Button type={'outline'} width={83} height={34} text={"保存"} onPress={() => { this._submitFn(0) }} />}
					<View style={{ marginLeft: 20 * scale }}>
						<Button text={"提交订单"} width={83} height={34} onPress={() => { this._submitFn(1) }} />
					</View>
				</View> */}
        {
          this.requesting ? (<View style={orderBaseStyle.statusStyle}><Loading /></View>) : null
        }
        {/* 底部弹框 */}
        <BouncedCpt isVisible={isVisible} data={{
          closeFn: () => { this._hideDetials(false) },
          renderBody: <BodyCpt key={1} data={{ orderFlag: this.orderFlag, priceData: this.showPrice }} closeFn={() => { this._hideDetials(false) }} />
        }} />
        <BottomCpt data={{
          isSssociated: true,
          totalGrossProfitAmtActive: this._totalGrossProfitAmt(), // 底部总毛利
          priceData: {
            data: this.showPrice,
            isProfit: true, // 是否有毛利的标
            callback: () => { this._hideDetials(true) }
          },
          btnData
        }} />

        {/* 计算明细详情 */}
        <BouncedCpt isVisible={isDetailsVisible} data={{
          closeFn: () => { this._hideDetialsTwo(false) },
          renderBody: <BodyCpt key={2} title={'毛利计算明细'} data={{ detailsDataAll: this.detailsDataAll, relation: true, orderFlag: this.orderFlag, priceData: this.showPrice }} closeFn={() => { this._hideDetialsTwo(false) }} />
        }} />

        <Common type="modal" demoData={(
          <Common type="listRadio" selectIndex={selectIndex} title={'报关港口'} listData={OD_ZXY_PORT} selectCallBack={this._selectCallBack} />
        )} isVisible={isModal} closeCallballFn={() => { this._toggle(false) }} />

      </View>
    )
  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#f7f7f7',
    paddingLeft: 12 * scale,
    paddingRight: 12 * scale
  },
  tabBox: {
    width: '100%',
    height: 34 * scale,
    borderWidth: 1 / PixelRatio.get(),
    borderColor: style.color.themeColor,
    flexDirection: 'row',
    alignItems: 'center',
  },
  xian: {
    borderBottomWidth: 1 / PixelRatio.get(),
    borderStyle: 'solid',
    borderBottomColor: '#E3E7F0',
  },
  itemTab: {
    width: '50%',
    height: 33 * scale,
    lineHeight: 33 * scale,
    textAlign: 'center',
    color: style.color.themeColor,
    backgroundColor: style.color.white,
  },
  itemTabActive: {
    backgroundColor: style.color.themeColor,
    color: style.color.white
  },
  subtitle: {
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center',
    marginTop: 10 * scale
  },
  rules: {
    textAlign: 'left',
    fontSize: 13 * scale,
    color: style.color.themeColor,
    paddingTop: 15 * scale,
    marginBottom: 5 * scale
  },
  total: {
    flex: 1,
    textAlign: 'right',
    fontSize: 13 * scale,
    paddingTop: 15 * scale,
    marginBottom: 5 * scale
  },
  colorActive: {
    color: style.color.lightRed
  },
  itemBox: {
    backgroundColor: style.color.white,
    width: '100%',
    borderRadius: 4 * scale,
    paddingTop: 10 * scale,
    paddingBottom: 10 * scale,
    paddingLeft: 12 * scale,
    paddingRight: 12 * scale,
    marginBottom: 20 * scale
  },
  head: {
    borderBottomWidth: 1 / PixelRatio.get(),
    borderStyle: 'solid',
    borderBottomColor: style.color.gray,
    position: 'relative',
    paddingBottom: 10 * scale
  },
  headBtn: {
    fontSize: 13 * scale,
    color: style.color.themeColor,
    //position: 'absolute',
    right: 0,
    top: 0,
    //marginBottom: 10 * scale
  },
  headBtnActive: {
    textAlign: 'right'
  },
  headTitle: {
    fontWeight: 'bold',
    color: style.color.black,
    marginBottom: 10 * scale
  },
  headInfo: {
    fontSize: 13 * scale,
  },
  contian: {
    paddingTop: 10 * scale,
    paddingBottom: 10 * scale,
    position: 'relative'
  },
  ctTitle: {
    fontSize: 12 * scale,
    lineHeight: 26 * scale,
    width: 290 * scale
  },
  ctItem: {
    flexDirection: 'row',
    alignItems: 'center',
  },
  ctItemLable: {
    color: '#999',
    width: 65 * scale,
    fontSize: 13 * scale,
  },
  ctItemText: {
    fontSize: 13 * scale,
    lineHeight: 26 * scale,
  },
  noData: {
    textAlign: 'center',
    paddingTop: 25 * scale,
    paddingBottom: 25 * scale
  },
  removeText: {
    fontSize: 11 * scale,
    lineHeight: 26 * scale,
    position: 'absolute',
    right: -10 * scale,
    top: 8 * scale,
    zIndex: 9,
    color: style.color.themeColor,
    paddingLeft: 10 * scale,
    paddingRight: 10 * scale,
  },
  btnBox: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    height: 50 * scale,
    backgroundColor: 'rgba(0,0,0,0)',
    position: 'absolute',
    bottom: 10 * scale,
    left: 0,
    width: '100%',
  },
  emptyView: {
    width: '100%',
    borderTopWidth: 1 / PixelRatio.get(),
    borderStyle: 'solid',
    borderTopColor: style.color.gray,
    paddingTop: 25 * scale,
    paddingBottom: 20 * scale,
    alignItems: 'center'
  },
  modalBox: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'rgba(0,0,0,0.5)',
  },
  rulesCont: {
    height: '80%',
    width: '90%',
    backgroundColor: '#fff',
    shadowColor: '#D2D2D2',
    // shadowOffset: { width: 6 * scale, height: 6 * scale },
    shadowRadius: 2,
    shadowOpacity: 0.5,
    borderRadius: 8 * scale
  },
  rulesTitle: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
  },
  rulesClose: {
    fontSize: 26 * scale,
    color: '#000',
    textAlign: 'right',
    marginRight: 12 * scale,
  },
  rulesTitleText: {
    fontSize: 16 * scale,
    color: '#000',
    textAlign: 'left',
    marginLeft: 12 * scale,
  },
  rulesTotalCard: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#f4f7fe',
    borderRadius: 8 * scale,
    margin: 12 * scale,
    padding: 12 * scale,
    marginBottom: 0
  },
  rulesTotalCardItem: {
    flex: 1,
  },
  rulesTotalCardLabel: {
    marginBottom: 10 * scale
  },
  rulesTotalProfit: {
    color: style.color.lightRed
  },
  rulesItemView: {
    margin: 12 * scale,
    borderBottomWidth: 1 / PixelRatio.get(),
    borderStyle: 'solid',
    borderBottomColor: style.color.gray,
  },
  rulesItem: {
    flexDirection: "row",
    alignItems: 'center',
    // justifyContent: 'center',
    marginBottom: 10 * scale,
  },
  rulesItemText: {
    flex: 1,
    fontSize: 13 * scale
  },
  rulesItemProfit: {
    color: style.color.lightRed,
    textAlign: 'right',
    marginBottom: 14 * scale,
    marginRight: 10 * scale,
    fontSize: 13 * scale
  },
  rulesItemHead: {
    marginBottom: 12 * scale,
    fontSize: 13 * scale
  },
  rulesItemTitleLeft: {
    marginTop: 8 * scale,
    marginBottom: 4 * scale,
    flex: 1,
    fontWeight: 'bold',
    fontSize: 13 * scale
  },
  rulesItemTitleRight: {
    marginTop: 8 * scale,
    marginBottom: 4 * scale,
    flex: 1,
    fontWeight: 'bold',
    fontSize: 13 * scale
  },
  ctInputBox: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingTop: 6 * scale,
    paddingBottom: 6 * scale
  },
  ctInput: {
    fontSize: 13 * scale,
    borderWidth: 1 / PixelRatio.get(),
    borderStyle: 'solid',
    borderColor: style.color.gray,
    height: 28 * scale,
    width: 35 * scale,
    marginRight: 5 * scale,
    paddingVertical: 0,
    textAlign: 'center'
  },
  gangkouSelect: {
    // height: 28 * scale,
    width: 140 * scale,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    borderWidth: 1 / PixelRatio.get(),
    borderStyle: 'solid',
    borderColor: style.color.gray,
    padding: 6 * scale,
    // paddingRight: 6 * scale,
  },
  ctInputText: {
    fontSize: 13 * scale,
  },
  ctInputTextRed: {
    color: style.color.lightRed
  },
  money: {
    paddingLeft: 5 * scale
  },
  rowbt: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between'
  },
  bold: {
    fontSize: 13 * scale,
    fontWeight: 'bold',
    color: '#060606'
  },
  rowItem: { flex: 1 },
  ptop: { paddingTop: 15 * scale, marginBottom: 15 * scale },
  norl: {
    color: '#333',
    fontSize: 13 * scale,
    paddingBottom: 5 * scale
  },
  colorRed: {
    fontSize: 13 * scale,
    color: '#E02020'
  },
  themeColor: {
    color: style.color.themeColor,
    fontSize: 11 * scale
  },
  infoBox: {
    paddingTop: 15 * scale,
    paddingBottom: 10 * scale,
  },
  info: {
    fontSize: 11 * scale,
    paddingBottom: 10 * scale,
    lineHeight: 16 * scale
  }
})